package com.amiu.shiro.db.user;

import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


public interface UserDao {

	public User selectByNameAndPwd(@Param("name")String name,@Param("pwd")String pwd);
	
	// 根据用户名查找用户  
	@Select("select id,username,password,password_salt,is_lock,description from user where username=#{name}")
	public User findByName(@Param("name")String name);
	
	@Select("select id,username,password,password_salt,is_lock,description from user where id=#{id}")
	public User findById(@Param("id")long id);
	
	/**
	 * createUser 和  createUserReturnId是两种不同的方法获取插入id
	 * 详见xml
	 */
	//创建账户
	public int createUser(User user); 
	
	public void createUserReturnId(@Param("user")User user); 
	
	//修改密码 
	@Update("UPDATE user SET password = #{user.password},password_salt = #{user.password_salt} WHERE id = #{user.id}")
    public void changePassword(@Param("user")User user);  
    //添加用户-角色关系  
    public void correlationRoles(Long userId, Long... roleIds); 
    // 移除用户-角色关系  
    public void uncorrelationRoles(Long userId, Long... roleIds);
    // 根据用户名查找其角色 
    public Map<Long,String> findRoles(String username); 
    //根据用户名查找其权限 
    public Map<Long,String> findPermissions(String username); 
	
}
